# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=readline
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_basever=7.0
_patchlevel=005
pkgver=${_basever}.${_patchlevel}
pkgrel=1
pkgdesc="MinGW port of readline for editing typed command lines (mingw-w64)"
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         #"${MINGW_PACKAGE_PREFIX}-ncurses"
         #"${MINGW_PACKAGE_PREFIX}-pdcurses"
         "${MINGW_PACKAGE_PREFIX}-termcap")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip')
license=('GPL')
url="https://cnswww.cns.cwru.edu/php/chet/readline/rltop.html"
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${_basever}.tar.gz"{,.sig}
        readline-7.0-mingw.patch)
if [ ${_patchlevel} -gt 00 ]; then
    for (( p=1; p<=$((10#${_patchlevel})); p++ )); do
        source=(${source[@]} https://ftp.gnu.org/gnu/${_realname}/${_realname}-${_basever}-patches/readline${_basever//./}-$(printf "%03d" $p){,.sig})
    done
fi
validpgpkeys=('7C0135FB088AAF6C66C650B9BB5869F064EA74AB')
sha256sums=('750d437185286f40a369e1e4f4764eda932b9459b5ec9a731628393dd3d32334'
            'SKIP'
            '9a4308f7d664d24154f1cbbaea8e1ae4bb716cbff01b8a707c541f70db6fc8cc'
            '9ac1b3ac2ec7b1bf0709af047f2d7d2a34ccde353684e57c6b47ebca77d7a376'
            'SKIP'
            '8747c92c35d5db32eae99af66f17b384abaca961653e185677f9c9a571ed2d58'
            'SKIP'
            '9e43aa93378c7e9f7001d8174b1beb948deefa6799b6f581673f465b7d9d4780'
            'SKIP'
            'f925683429f20973c552bff6702c74c58c2a38ff6e5cf305a8e847119c5a6b64'
            'SKIP'
            'ca159c83706541c6bbe39129a33d63bbd76ac594303f67e4d35678711c51b753'
            'SKIP')

prepare() {
  cd "${srcdir}/readline-${_basever}"

  for (( p=1; p<=$((10#${_patchlevel})); p++ )); do
    msg "applying patch readline${_basever//./}-$(printf "%03d" $p)"
    patch -Np0 -i ${srcdir}/readline${_basever//./}-$(printf "%03d" $p)
  done

  patch -Np1 -i ${srcdir}/readline-7.0-mingw.patch
  # Remove RPATH from shared objects (FS#14366)
  sed -i 's|-Wl,-rpath,$(libdir) ||g' support/shobj-conf
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}-${_basever}/configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --enable-shared \
    --without-curses
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make install DESTDIR="${pkgdir}"
}
